import {
  Message
} from 'element-ui'
var verification = {
  realNameCode(classVal) {
    var reg = /^[a-zA-Z\u2E80-\u9FFF][a-z0-9A-Z\u2E80-\u9FFF]{0,19}$/;
    if (!reg.test(classVal)) {
      return "请输入由1-20位英文，数字，汉字的姓名";
    } else {
      return true;
    }
  },
  userNameCode(classVal) {
    var reg = /^[a-zA-Z]\w{5,19}$/;
    if (!reg.test(classVal)) {
      return "请输入由6-20位英文，数字，_的名称";
    } else {
      return true;
    }
  },
  passwordCode(classVal) {
    var regs = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,32}$/;
    //var regs = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,32}$/;
    if (!regs.test(classVal)) {
      return "请输入6-32 位字符，不能与用户名相同，且字母、数字、符号至少包含两种的密码";
    } else {
      return true;
    }
  },
  telphoneCode(classVal) {
    if (!(/^1[34578]\d{9}$/.test(classVal))) {
      return "请输入正确电话号码";
    } else {
      return true;
    }
  },
  emailCode(data) {
    if (!(/^[a-zA-Z0-9]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(data)) && data !== "") {
      return "请输入正确邮箱号码";
    } else {
      return true;
    }
  },
  spaceCode(classVal) {
    var regy = /\s/g;
    if (regy.test(classVal)) {
      return "不能输入空格";
    } else {
      return true;
    }
  },
  specialCode(classVal) {
    var reg = /[\@\/\'\\\"#$%&\^\*]/g;
    if (reg.test(classVal)) {
      return "不能输入特殊字符(@/'\"#$%&^*)";
    } else {
      return true;
    }
  },
  emptyCode(data, message) {
    if (data == "") {
      return message + "不能为空";
    } else {
      return true;
    }
  },
  formatDate(now) {
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();

    return year + "-" + month + "-" + date + "   " + hour + ":" + minute;
  },
  proving(veri_lon, switchs) {
    var veri = this;
    var bool = true;
    verFun: {
      for (let i in veri_lon) {
        let types = veri_lon[i].type;
        for (let j in types) {
          let result = veri[types[j]](veri_lon[i].data, veri_lon[i].name);
          if (result !== true) {
            if (!switchs) {
              Message({
                message: result,
                type: 'error'
              });
            }
            bool = false;
            break verFun;
          }
        }
      }
    }
    return bool;

  }

};
export default verification;
